package com.ruoyi.labdata.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labdata.domain.LabFlowNode;
import com.ruoyi.labdata.service.ILabFlowNodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流程节点Controller
 * 
 * @author winner pan
 * @date 2022-03-06
 */
@RestController
@RequestMapping("/labdata/flowNode")
public class LabFlowNodeController extends BaseController {
	@Autowired
	private ILabFlowNodeService labFlowNodeService;

	/**
	 * 查询流程节点列表
	 */
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabFlowNode labFlowNode) {
		// startPage();
		List<LabFlowNode> list = labFlowNodeService.selectLabFlowNodeList(labFlowNode);
		return getDataTable(list);
	}
	
	@GetMapping("/listFlowNodes/{workflowId}")
	public AjaxResult getAllFlowNodes(@PathVariable Long workflowId) {
		LabFlowNode node = new LabFlowNode();
		node.setWorkflowId(workflowId);
		List<LabFlowNode> list = labFlowNodeService.selectLabFlowNodeList(node);
		return AjaxResult.success(list);
	}

	/**
	 * 导出流程节点列表
	 */
	//@PreAuthorize("@ss.hasPermi('labdata:flowNode:export')")
	/*@Log(title = "流程节点", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(LabFlowNode labFlowNode) {
		List<LabFlowNode> list = labFlowNodeService.selectLabFlowNodeList(labFlowNode);
		ExcelUtil<LabFlowNode> util = new ExcelUtil<LabFlowNode>(LabFlowNode.class);
		return util.exportExcel(list, "flowNode");
	}*/

	/**
	 * 获取流程节点详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:query')")
	@GetMapping(value = "/{nodeId}")
	public AjaxResult getInfo(@PathVariable("nodeId") Long nodeId) {
		return AjaxResult.success(labFlowNodeService.selectLabFlowNodeById(nodeId));
	}

	/**
	 * 新增流程节点
	 */
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:edit')")
	@Log(title = "流程节点", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabFlowNode labFlowNode) {
		return toAjax(labFlowNodeService.insertLabFlowNode(labFlowNode));
	}

	/**
	 * 修改流程节点
	 */
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:edit')")
	@Log(title = "流程节点", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabFlowNode labFlowNode) {
		return toAjax(labFlowNodeService.updateLabFlowNode(labFlowNode));
	}
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:edit')")
	@Log(title = "流程节点", businessType = BusinessType.UPDATE)
	@PutMapping("/saveSort")
	public AjaxResult updateNo(@RequestBody List<LabFlowNode> labFlowNodeList) {
		return toAjax(labFlowNodeService.updateLabFlowNodeNo(labFlowNodeList));
	}

	/**
	 * 删除流程节点
	 */
	@PreAuthorize("@ss.hasPermi('labdata:flowDefination:edit')")
	@Log(title = "流程节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nodeId}")
	public AjaxResult remove(@PathVariable Long nodeId) {
		return toAjax(labFlowNodeService.deleteLabFlowNodeById(nodeId));
	}
}
